package com.blink.optimize.apis.collect;

import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
 * <Description> </Description>
 * <ClassName> TestHashSet</ClassName>
 *
 * @Author liuxianzhao
 * @Date 2018年01月08日 13:04
 */
public class TestHashSet {
    @Test
    public void testHashSet() {
        Set<Name> s = new HashSet<>();
        s.add(new Name("liu","xianzhao"));
        System.out.println(s.contains(new Name("liu","xianzhao")));

    }

    class Name {
        private String firstName;
        private String lastName;

        public Name(String firstName, String lastName) {
            this.firstName = firstName;
            this.lastName = lastName;
        }

        @Override
        public int hashCode() {
            return Objects.hash(firstName, lastName);
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj) {
                return true;
            }
            if (obj.getClass() == Name.class) {
                Name tmp = (Name) obj;
                return Objects.equals(this.firstName, tmp.firstName)
                        && Objects.equals(this.lastName, tmp.lastName);
            }
            return false;
        }

        public String getFirstName() {
            return firstName;
        }

        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }

        public String getLastName() {
            return lastName;
        }

        public void setLastName(String lastName) {
            this.lastName = lastName;
        }
    }
}
